package com.yangle.bootdemo.controller;

import com.yangle.bootdemo.pojo.Article;
import com.yangle.bootdemo.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/findAllPage/page/{page}/pageSize/{pageSize}")
    public String findAll(Model model, @PathVariable Integer page,@PathVariable Integer pageSize){
        if(page <= 0){
            page = 1;
        }
        Map<String,Object> map = articleService.findAllArticle(page,pageSize);
        model.addAttribute("articles",map.get("list"));
        model.addAttribute("total",map.get("total"));
        model.addAttribute("cPage",map.get("cPage"));
        model.addAttribute("prPage",map.get("prPage"));
        model.addAttribute("laPage",map.get("laPage"));
        return "client/index";
    }

    @GetMapping("/findAllPage")
    public String findAll(Model model){
        Map<String,Object> map = articleService.findAllArticle(1,2);
        model.addAttribute("articles",map.get("list"));
        model.addAttribute("total",map.get("total"));
        model.addAttribute("cPage",map.get("cPage"));
        model.addAttribute("prPage",map.get("prPage"));
        model.addAttribute("laPage",map.get("laPage"));
        return "client/index";
    }


}
